/**
 * 
 */
package co.gov.medellin.sdep.sisdep.regulacion.service;

import java.util.Date;
import java.util.List;

import co.gov.medellin.sdep.sisdep.regulacion.exception.FeriaDecSteoVeedorException;
import co.gov.medellin.sdep.sisdep.regulacion.exception.FeriaDecSteoVeedorRuntimeException;
import co.gov.medellin.sdep.sisdep.regulacion.exception.descriptor.FeriaDecSteoVeedorMessageDescriptor;
import co.gov.medellin.sdep.sisdep.common.message.MessageDescriptorConstant;
import co.gov.medellin.sdep.sisdep.common.service.BaseService;
import co.gov.medellin.sdep.sisdep.model.FeriaDecSteoVeedor;
import co.gov.medellin.sdep.sisdep.model.dao.impl.IFeriaDecSteoVeedorDAOT;

/**
 * @author Usuario
 *
 */
public class FeriaDecSteoVeedorServiceImpl extends BaseService implements IFeriaDecSteoVeedorService {

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                 init()
	//----------------------------------------------------------------------

	/**
	 * default serial version
	 */
	private static final long serialVersionUID = 1L;
	/** */
	private IFeriaDecSteoVeedorDAOT feriaDecSteoVeedorDAO;

	/**
	 * 
	 */
	public FeriaDecSteoVeedorServiceImpl() {
	}

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                  end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                     init()
	//----------------------------------------------------------------------

	/**
	 * 
	 */
	public void insert(FeriaDecSteoVeedor feriaDecSteoVeedor) throws FeriaDecSteoVeedorException {
		try{
			feriaDecSteoVeedor.setUsuarioCrea(getPrincipalUser());
			feriaDecSteoVeedor.setFechaCrea(new Date());
			getFeriaDecSteoVeedorDAO().insert(feriaDecSteoVeedor);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new FeriaDecSteoVeedorException(new FeriaDecSteoVeedorMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new FeriaDecSteoVeedorException(new FeriaDecSteoVeedorMessageDescriptor(MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void update(FeriaDecSteoVeedor feriaDecSteoVeedor) throws FeriaDecSteoVeedorException {
		try{
			feriaDecSteoVeedor.setUsuarioModifica(getPrincipalUser());
			feriaDecSteoVeedor.setFechaModifica(new Date());
			getFeriaDecSteoVeedorDAO().update(feriaDecSteoVeedor);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new FeriaDecSteoVeedorRuntimeException(new FeriaDecSteoVeedorMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new FeriaDecSteoVeedorRuntimeException(new FeriaDecSteoVeedorMessageDescriptor(MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void delete(FeriaDecSteoVeedor feriaDecSteoVeedor) throws FeriaDecSteoVeedorException {
		try {
			feriaDecSteoVeedor.setUsuarioModifica(getPrincipalUser());
			feriaDecSteoVeedor.setFechaModifica(new Date());
			getFeriaDecSteoVeedorDAO().delete(feriaDecSteoVeedor);
		}catch (Exception e) {
			Object [] infoError = {
			};
			throw new FeriaDecSteoVeedorRuntimeException(new FeriaDecSteoVeedorMessageDescriptor(MessageDescriptorConstant.DELETE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List load(int start,int max, FeriaDecSteoVeedor feriaDecSteoVeedor) throws FeriaDecSteoVeedorException {
		try{
			//return getFeriaDecSteoVeedorDAO().getAllFeriaDecSteoVeedorPaginated(start, max, criteria);
			return getFeriaDecSteoVeedorDAO().load();
		}catch (Exception e) {
			Object [] infoError = null;
			throw new FeriaDecSteoVeedorRuntimeException(new FeriaDecSteoVeedorMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}
	
	/**
	 * @return 
	 * 
	 */
	public final List loadByAnio(int start,int max, FeriaDecSteoVeedor feriaDecSteoVeedor) throws FeriaDecSteoVeedorException {
		try{
			//return getFeriaDecSteoVeedorDAO().getAllFeriaDecSteoVeedorPaginated(start, max, criteria);
			return getFeriaDecSteoVeedorDAO().loadByAnio( feriaDecSteoVeedor);
		}catch (Exception e) {
			Object [] infoError = null;
			throw new FeriaDecSteoVeedorRuntimeException(new FeriaDecSteoVeedorMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	/**
	 * 
	 */
	public final FeriaDecSteoVeedor get(long id) throws FeriaDecSteoVeedorException {
		try{
			return getFeriaDecSteoVeedorDAO().findByPrimaryKey(id);
		}catch (Exception e) {
			Object [] infoError = {new Long(id)};
			throw new FeriaDecSteoVeedorRuntimeException(new FeriaDecSteoVeedorMessageDescriptor(MessageDescriptorConstant.GET), infoError, e);
		}
	}

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                      end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- getters and setters                                         init()
	//----------------------------------------------------------------------

	/**
	 * @author Usuario
	 *
	 */
	public IFeriaDecSteoVeedorDAOT getFeriaDecSteoVeedorDAO() {
		return feriaDecSteoVeedorDAO;
	}

	/**
	 * @author Usuario
	 *
	 */
	public void setFeriaDecSteoVeedorDAO(IFeriaDecSteoVeedorDAOT feriaDecSteoVeedorDAO) {
		this.feriaDecSteoVeedorDAO = feriaDecSteoVeedorDAO;
	}

	//----------------------------------------------------------------------
	//--- getters and setters                                          end()
	//----------------------------------------------------------------------

}
